#!/usr/bin/env python
# coding=utf-8
__author__ = 'Administrator'

def obtain_html():
    idcards = [350124198604220155,320581199706262717]
    import httplib2,re
    httplib2.debuglevel = 0
    from urllib import urlencode
    h = httplib2.Http()

    regx_list = []
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x5ba2;&#x6237;&#x59d3;&#x540d;:</td>\s*<td class="right" align="right">(?P<name>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x8bc1;&#x4ef6;&#x7c7b;&#x578b;:</td>\s*<td class="right" align="right">(?P<idcard>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x7533;&#x8bf7;&#x65e5;&#x671f;:</td>\s*<td class="right" align="right">(?P<applydata>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x4ea7;&#x54c1;&#x540d;&#x79f0;:</td>\s*<td class="right" align="right">(?P<product>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x5361;&#x79cd;:</td>\s*<td class="right" align="right">(?P<cardtype>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x5e01;&#x79cd;:</td>\s*<td class="right" align="right">(?P<moneytype>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x7533;&#x8bf7;&#x8868;&#x6765;&#x6e90;:</td>\s*<td class="right" align="right">(?P<refer>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x5ba1;&#x6279;&#x72b6;&#x6001;:</td>\s*<td class="right" align="right">(?P<status>.+?)</td>\s*</tr>\s*')
    regx_list.append(r'<tr>\s*<td class="left" style="width:120px">&#x5ba1;&#x6279;&#x901a;&#x8fc7;&#x65e5;&#x671f;:</td>\s*<td class="right" align="right">(?P<approvedata>.+?)</td>\s*</tr>')
    regx =  ''.join(regx_list)

    response,content = h.request("https://wx.abchina.com/WebSite/CardStatusAuthenticationAct.ebf")
    print response
    return

    headers = {'Content-type': 'application/x-www-form-urlencoded',
               "Host":"wx.abchina.com",
               "Origin":"https://wx.abchina.com",
               "Referer":"https://wx.abchina.com/WebSite/CardStatusAuthenticationAct.ebf",
               "User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.5 Safari/537.36",
               "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
               "Accept-Encoding":"gzip,deflate,sdch",
               "Accept-Language":"zh-CN,zh;q=0.8,en;q=0.6,nl;q=0.4,zh-TW;q=0.2",
               "Cookie":response['set-cookie']}
    post_data = urlencode(dict(cCertType="I", iCertId="350124198604220155", openId="oHFX_jqLqUeHgkFB-0n-6H6Mxe98", appId="wx51fdf61c0de4ab0b"))\
        .encode('utf-8')
    response,content = h.request("https://wx.abchina.com/WebSite/CardStatusQueryAct.ebf","Post",body=post_data,headers=headers)

    rs = re.search(regx,content)
    if rs:
        print rs.group('approvedata')
    else:
        print 'nothing'

if __name__ == '__main__':
    obtain_html()